package com.sunhy.redisbloom1.controller;

import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RMapCache;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;

@Slf4j
@RestController
public class RedissonController {

    @Autowired
    RedissonClient redissonClient;

    @GetMapping("/test")
    public String test() {
        new Thread(() -> {
            RMapCache<String, Boolean> map = redissonClient.getMapCache("MyBloom4");
            map.fastPut("ngg4e038", true, 10, TimeUnit.SECONDS);
            map.fastPut("ngg4e022", true);
            map.fastPut("ngg4e011", true);

            try {
                Thread.sleep(5000);
                map.remove("ngg4e022");
                Set<String> ss1 = map.keySet();
                Map<String, Boolean> map1 = map.getAll(ss1);
                log.info("5s元素列表：{} ", map1);

                Thread.sleep(5000);
                Set<String> ss2 = map.keySet();
                Map<String, Boolean> map2 = map.getAll(ss2);
                log.info("又5s元素列表：{} ", map2);

            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }).start();

        return "Success";
    }

}
